package cn.edu.tju.core.security.repository;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import cn.edu.tju.core.model.User;

import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {

   @EntityGraph(attributePaths = "authorities")
   Optional<User> findOneWithAuthoritiesByUsername(String username);
   
   @EntityGraph(attributePaths = "authorities")
   Optional<User> findOneWithAuthoritiesByPhoneNumber(String phoneNumber);

//   @EntityGraph(attributePaths = "authorities")
//   Optional<User> findOneWithAuthoritiesByEmailIgnoreCase(String email);

   // 根据用户名查询用户(检查用户名是否已存在)
   Optional<User> findOneByUsername(String username);
   
   // 根据手机号查询用户(检查手机号是否已存在)
   Optional<User> findOneByPhoneNumber(String phoneNumber);

}
